import 'dart:convert';
import 'dart:async';
import 'package:flutterxc/module/travel_model.dart';
import 'package:http/http.dart' as http;
//import 'package:flutterxc/module/Home_module.dart';
//旅拍页的dao
//const Travel_URL = 'http://www.devio.org/io/flutter_app/json/travel_page.json';
var Params = {
  "districtId": -1,
  "groupChannelCode": "RX-OMF",
  "type": null,
  "lat": -180,
  "lon": -180,
  "locatedDistrictId": 0,
  "pagePara": {
    "pageIndex": 1,
    "pageSize": 10,
    "sortType": 9,
    "sortDirection": 0
  },
  "imageCutType": 1,
  "head": {'cid': "09031014111431397988"},
  "contentType": "json"
};

class TravelDao {
  static Future<TravelModel> fetch(String url,String groupChannelCode,int pageIndex,int pageSize)async {
    Map paramsMap = Params['pagePara'];
    paramsMap['pageIndex'] = pageIndex;
    paramsMap['pageSize'] = pageSize;
    Params['groupChannelCode'] = groupChannelCode;
    final response = await http.post(url,body:jsonEncode(Params) );
    if(response.statusCode == 200){
      var res = json.decode(Utf8Decoder().convert(response.bodyBytes));
      return TravelModel.fromJson(res);
    }else {
      throw Exception('一个未知的错误');
    }
  }
}